﻿using Dapper;
using ET_DbCommon.Model;
using NPOI.POIFS.Crypt.Standard;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ET_DbCommon.DAL
{
    public class SceneFileDAL
    {
        public static int Update(SceneFileModel model)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                return MySQLExt.UpdateById(conn, model);
            }

        }

        public static List<SceneFileModel> GetAllIgnoreFile()
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                string sql = "SELECT Id, SceneFileName, UsedQuestions FROM scenefile";
                return conn.Query<SceneFileModel>(sql).ToList();
            }
        }

        public static List<SceneFileModel> GetSceneFile(int sceneId)
        {
            using(var conn = MySqlHelper.GetConnection())
            {
                string sql = $"SELECT Id, SceneFileName, SceneFile, UsedQuestions FROM scenefile Where Id = {sceneId}";
                return conn.Query<SceneFileModel>(sql).ToList();
            }
        }

        public static void Insert(List<SceneFileModel> models)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                foreach (var model in models)
                {
                    MySQLExt.InsertIdentityIndex(conn, model);
                }
            }
        }

        public static int Insert(SceneFileModel model)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                return MySQLExt.InsertIdentityIndex(conn, model);
            }
        }

        public static int Delete(SceneFileModel model)
        {
            using (var conn = MySqlHelper.GetConnection())
            {
                return MySQLExt.DeleteById<SceneFileModel>(conn, model.Id);
            }
        }
    }
}
